//
//  ListenViewController.m
//  LoveListen
//
//  Created by 王喆 on 15/7/1.
//  Copyright (c) 2015年 王喆. All rights reserved.
//

#import "ListenViewController.h"
#import "LZXHelper.h"
#import "MyControl.h"
#import "ListenDetailController.h"
#import "ListenModel.h"

@interface ListenViewController ()

@end

@implementation ListenViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self showUI];
    self.view.backgroundColor  =[UIColor whiteColor];
    self.navigationController.title = @"听书城";
    self.automaticallyAdjustsScrollViewInsets = YES;

}

-(void)showUI{
    UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"backImg2"]];
    imageView.frame = self.view.bounds;
    imageView.alpha = 0.25;
    [self.view addSubview:imageView];
    
    NSArray *imagesNames = @[@"setting_about",@"setting_appad",@"setting_loglistenpos",@"setting_wakeup",@"setting_net",@"setting_wakeup",@"setting_wakeup",@"setting_wakeup",@"setting_wakeup",@"setting_wakeup",@"setting_wakeup"];
    NSArray *titles = @[@"全部",@"笑话段子",@"脱口秀",@"恋爱宝典",@"冷笑话",@"涨姿势",@"聊电影",@"访谈秀",@"方言秀",@"神吐槽",@"万和频道"];

    //横向的间隔
    CGFloat wSpace = ([LZXHelper getScreenSize].width - 4*57)/5;
    
    //纵向的间隔
    CGFloat hSpace = ([LZXHelper getScreenSize].height-64-49 - 4*57)/5;
    for (int i = 0; i<imagesNames.count; i++) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.tag = 101+i;
        [btn setImage:[UIImage imageNamed:imagesNames[i]] forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
        btn.layer.masksToBounds = YES;
        btn.layer.cornerRadius = 8;
        //九宫格坐标的小算法:(横坐标:i%横向显示个数的最大值;纵坐标:i/纵向的个数的最大值)
        [btn setFrame:CGRectMake(wSpace +(i%4)*(57+wSpace),20+hSpace +(i/4)*(hSpace+57), 57,57)];
        [self.view addSubview:btn];
        
        //创建label
        UILabel *label = [MyControl creatLabelWithFrame:CGRectMake(wSpace+(i%4)*(57+wSpace),20+hSpace+57 + (i/4)*(hSpace+57), 57, 20) text:titles[i]];
        label.font = [UIFont systemFontOfSize:12];
        label.textAlignment = NSTextAlignmentCenter;
        [self.view addSubview:label];
        
        
    }
}
#pragma mark - 按钮触发的函数
- (void)btnClicked:(UIButton *)button{
    switch (button.tag) {
        case 101:
        {
            ListenDetailController *listen = [[ListenDetailController alloc]init];
                listen.str = @"all";
            [self.navigationController pushViewController:listen animated:YES];
            
        
        }
            break;
        case 102:
        {
            ListenDetailController *listen = [[ListenDetailController alloc]init];
            listen.str = @"%E7%AC%91%E8%AF%9D%E6%AE%B5%E5%AD%90";
            [self.navigationController pushViewController:listen animated:YES];
            
            
        }
            break;
        case 103:
        {
            ListenDetailController *listen = [[ListenDetailController alloc]init];
            listen.str = @"%E8%84%B1%E5%8F%A3%E7%A7%80";
            [self.navigationController pushViewController:listen animated:YES];
            
            
        }
            break;
        case 104:
        {
            ListenDetailController *listen = [[ListenDetailController alloc]init];
            listen.str = @"%E6%81%8B%E7%88%B1%E5%AE%9D%E5%85%B8";
            [self.navigationController pushViewController:listen animated:YES];
            
            
        }
            break;
        case 105:
        {
            ListenDetailController *listen = [[ListenDetailController alloc]init];
            listen.str = @"%E5%86%B7%E7%AC%91%E8%AF%9D";
            [self.navigationController pushViewController:listen animated:YES];
            
            
        }
            break;
        case 106:
        {
            ListenDetailController *listen = [[ListenDetailController alloc]init];
            listen.str = @"%E6%B6%A8%E5%A7%BF%E5%8A%BF";
            [self.navigationController pushViewController:listen animated:YES];
            
            
        }
            break;
        case 107:
        {
            ListenDetailController *listen = [[ListenDetailController alloc]init];
            listen.str = @"%E8%81%8A%E7%94%B5%E5%BD%B1";
            [self.navigationController pushViewController:listen animated:YES];
            
            
        }
            break;
        case 108:
        {
            ListenDetailController *listen = [[ListenDetailController alloc]init];
            listen.str = @"%E8%AE%BF%E8%B0%88%E7%A7%80";
            [self.navigationController pushViewController:listen animated:YES];
            
            
        }
            break;
        case 109:
        {
            ListenDetailController *listen = [[ListenDetailController alloc]init];
            listen.str = @"%E6%96%B9%E8%A8%80%E7%A7%80";
            [self.navigationController pushViewController:listen animated:YES];
            
            
        }
            break;
        case 110:
        {
            ListenDetailController *listen = [[ListenDetailController alloc]init];
            listen.str = @"%E7%A5%9E%E5%90%90%E6%A7%BD";
            [self.navigationController pushViewController:listen animated:YES];
            
            
        }
            break;
        case 111:
        {
            ListenDetailController *listen = [[ListenDetailController alloc]init];
            listen.str = @"%E4%B8%87%E5%90%88%E9%A2%91%E9%81%93";
            [self.navigationController pushViewController:listen animated:YES];
            
            
        }
            break;
        
            
        default:
            break;
    }
    
    
    
    
    
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    }



@end
